/**
 * Alibaba.com.cn Inc.
 * Copyright (c) 2004-2021 All Rights Reserved.
 */
package com.starlink.utils;

import cn.hutool.core.util.NumberUtil;
import com.starlink.common.enums.ErrorCode;
import com.starlink.common.utils.AssertUtil;

/**
 * @author zhanghong
 * @version MoneyUtil.java, v 0.1 2022/4/9 15:06 下午 MoneyUtil Exp $$
 */
public class MoneyUtil {

    /**
     * 元转分-四舍五入
     * @return
     */
    public static long yuan2fen(Double money) {
        AssertUtil.assertNotNull(money, ErrorCode.PARAM_ERROR, "转换失败");
        return NumberUtil.mul(NumberUtil.round(money, 2), 100).longValue();
    }

    /**
     * 分转元-四舍五入
     * @return
     */
    public static Double fen2yuan(long money) {
        return NumberUtil.div(money, 100, 2);
    }
}
